package controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

import kit.BaseResponse;
import service.MyUserService;

public class MyUserController  extends Controller{
	MyUserService service = new MyUserService();
	public void loginPage() {
		this.redirect("/views/index.html");
	}
	//登陆
	public void login() {
		BaseResponse response = new BaseResponse();
		
		String account = this.getPara("account");
		String pass = this.getPara("pass");
		Record users;
		if((users = service.login(account, pass))!=null) {
			this.setSessionAttr("u_id", users.get("u_id"));
			this.setSessionAttr("u_upper", users.get("u_upper"));
			this.setSessionAttr("u_grade", users.get("u_grade"));
			response.setData(users);
		}
		
		this.renderJson(response);
	}
	
	public void getOwnReportList() {
		BaseResponse response = new BaseResponse();
		
		int u_id = this.getSessionAttr("u_id");
		int u_grade = this.getSessionAttr("u_grade");
		List<Record> reportList = null;
		if(u_grade == 2) {
			reportList = service.getGrade2OwnReportList(u_id);
		}else if(u_grade == 3){
			reportList = service.getGrade3OwnReportList(u_id);
		}
		response.setData(reportList);
		
		this.renderJson(response);
	}
	
	public void getDownReportList() {
		BaseResponse response = new BaseResponse();
		
		int u_id = this.getSessionAttr("u_id");
		int u_grade = this.getSessionAttr("u_grade");
		List<Record> reportList = null;
		if(u_grade == 1) {
			
		}else if(u_grade == 2){
			
		}
		response.setData(reportList);
		
		this.renderJson(response);
	}
	
	public void submitReport() {
		BaseResponse response = new BaseResponse();
		
		int u_id = this.getSessionAttr("u_id");
		int u_grade = this.getSessionAttr("u_grade");
		Integer u_upper = this.getSessionAttr("u_upper");
		if(u_grade == 2) {
			
		}else if(u_grade == 3) {
			String g3_content = this.getPara("g3_content");
			String g3_get = this.getPara("g3_get");
			String g3_job = this.getPara("g3_job");
			String g3_need = this.getPara("g3_need");
			System.out.println(g3_content+" "+g3_get+" "+g3_job+" "+g3_need);
			service.saveGrade3Report(u_id,g3_content,g3_get,g3_job,g3_need);
		}
		
		this.renderJson(response);
	}
}
